/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VolumeAdjustFrame.java
 *
 * Created on Jun 2, 2011, 10:51:37 AM
 */

package gbbmgmt;

import java.util.*;
import org.jdesktop.application.Action;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class VolumeAdjustFrame extends javax.swing.JFrame {

    public ArrayList<String[]> State;

    public String BrewID = "0";

    /** Creates new form VolumeAdjustFrame */
    public VolumeAdjustFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextFieldVessel = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldCurVol = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldNewVol = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldBrew = new javax.swing.JTextField();
        jButtonUpdate = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldCurState = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jComboBoxNewState = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(VolumeAdjustFrame.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextFieldVessel.setEditable(false);
        jTextFieldVessel.setText(resourceMap.getString("jTextFieldVessel.text")); // NOI18N
        jTextFieldVessel.setName("jTextFieldVessel"); // NOI18N
        jTextFieldVessel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldVesselActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldCurVol.setEditable(false);
        jTextFieldCurVol.setName("jTextFieldCurVol"); // NOI18N
        jTextFieldCurVol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCurVolActionPerformed(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldNewVol.setName("jTextFieldNewVol"); // NOI18N
        jTextFieldNewVol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNewVolActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jTextFieldBrew.setEditable(false);
        jTextFieldBrew.setName("jTextFieldBrew"); // NOI18N
        jTextFieldBrew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBrewActionPerformed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(VolumeAdjustFrame.class, this);
        jButtonUpdate.setAction(actionMap.get("Update")); // NOI18N
        jButtonUpdate.setText(resourceMap.getString("jButtonUpdate.text")); // NOI18N
        jButtonUpdate.setName("jButtonUpdate"); // NOI18N

        jButtonCancel.setAction(actionMap.get("CancelBtn")); // NOI18N
        jButtonCancel.setText(resourceMap.getString("jButtonCancel.text")); // NOI18N
        jButtonCancel.setName("jButtonCancel"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldCurState.setEditable(false);
        jTextFieldCurState.setName("jTextFieldCurState"); // NOI18N
        jTextFieldCurState.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCurStateActionPerformed(evt);
            }
        });

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jComboBoxNewState.setName("jComboBoxNewState"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldNewVol, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                        .addComponent(jButtonUpdate))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jComboBoxNewState, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                        .addComponent(jButtonCancel)))
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldBrew)
                    .addComponent(jTextFieldVessel)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldCurVol, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCurState, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldBrew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldVessel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldCurVol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldCurState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jButtonUpdate)
                    .addComponent(jTextFieldNewVol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonCancel)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jComboBoxNewState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldVesselActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldVesselActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldVesselActionPerformed

    private void jTextFieldCurVolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCurVolActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCurVolActionPerformed

    private void jTextFieldNewVolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNewVolActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNewVolActionPerformed

    private void jTextFieldBrewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldBrewActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBrewActionPerformed

    private void jTextFieldCurStateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCurStateActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCurStateActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VolumeAdjustFrame().setVisible(true);
            }
        });
    }

    public void LoadList(String BID, String FVID){
        DBA.openDBCon();
        State = DBA.RunSQLQuery("SELECT StateID,StateDesc FROM State");
        DBA.GetBrewsData(BID);
        DBA.GetBeerData(Integer.toString(DBA.BBeerID));
        DBA.GetStateData(Integer.toString(DBA.BState));
        DBA.closeDBCon();

        for(String s[] : State){
            jComboBoxNewState.addItem(s[0] + " - " + s[1]);
        }

        jTextFieldBrew.setText(BID + " - " + DBA.BName);
        jTextFieldVessel.setText(FVID);
        jTextFieldCurVol.setText(Float.toString(DBA.VolLeft));
        jTextFieldCurState.setText(Integer.toString(DBA.BState));

        BrewID = BID;
    }

    @Action
    public void CancelBtn() {
        dispose();
    }

    @Action
    public void Update() {
        String Volume = jTextFieldNewVol.getText();
        String ste = "0";

        String cmpr = jComboBoxNewState.getSelectedItem().toString();

        for(String s[] : State){
            String tmp = s[0] + " - " + s[1];
            if (cmpr.equals(tmp)){
                ste = s[0];
            }
        }

        int response = JOptionPane.showConfirmDialog(null,
                "This will modify brew " + Integer.toString(DBA.BID) + " - " +
                DBA.BName + " to " + Volume + " BBL and State " + ste + ", Continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            DBA.openDBCon();

            String query = "UPDATE Brews SET VolLeft='" +
                        Volume + "',BState='" +
                        ste + "' WHERE BID = '" + BrewID + "'";
            DBA.RunSQLUpdateQuery(query);
            DBA.closeDBCon();
        }

        dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JComboBox jComboBoxNewState;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextFieldBrew;
    private javax.swing.JTextField jTextFieldCurState;
    private javax.swing.JTextField jTextFieldCurVol;
    private javax.swing.JTextField jTextFieldNewVol;
    private javax.swing.JTextField jTextFieldVessel;
    // End of variables declaration//GEN-END:variables

}
